package com.ssm.demo.controller;

import com.ssm.demo.pojo.Test;
import com.ssm.demo.service.TestService;
import com.ssm.demo.util.PageBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

import java.util.concurrent.TimeUnit;

/**
 * @author Zhang Yu
 * @description: TODO
 * @date 2024/3/27 7:25
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    TestService testService;
    @Autowired
    RedisTemplate redisTemplate;
    @PostMapping
    public Object add(Test test) {
        return testService.insertSelective(test);
    }

    @GetMapping
    public Object select(HttpServletRequest request){
        PageBean pageBean = new PageBean();
        pageBean.setRequest(request);
        return  testService.selectPager(pageBean);
    }

    @GetMapping("/testRedis")
    public String testRedis(){
        redisTemplate.opsForValue().set("test_cache","test",20, TimeUnit.MINUTES);
        return "redis操作成功";
    }

    @GetMapping("/exception")
    public String testException(){
        return testService.testException();
    }

}
